﻿package org.openChart.display 
{
	import flash.geom.Point;
	import org.openChart.meta.Axis;
	import org.openChart.util.Rectangle;
	
	
	/**
	 * The X-Axis of the coordinates.
	 * 
	 * @author Chongyuan
	 */
	public class DisplayAxis extends DisplayBaseObject implements DisplayInterface
	{
		private var title_:DisplayTextLabel;
		
		private var startPoint_:Point;
		private var endPoint_:Point;
		private var width_:Number;
		
		private var labels_:DisplayLabelGroup;
		private var sticks_:DisplayStickGroup;
		
		private var parent_:DisplayBarChart;
		
		public function DisplayAxis( axis:Axis, chart:DisplayBarChart ) 
		{
			this.parent_ = chart;
			super(axis);
		}
		
		public override function initialize():void
		{
			labels_ = new DisplayLabelGroup();
			sticks_ = new DisplayStickGroup();
			title_ = new DisplayTextLabel(axis.title);
			this.width = axis.getStyle().width;
			super.initialize();
		}
		
		public override function resize(rectangle:Rectangle):void
		{
			super.resize(rectangle);
		}
		
		public function get startPoint():Point
		{
			return startPoint_;
		}
		
		public function get endPoint():Point
		{
			return endPoint_;
		}
		
		public function set startPoint( startPoint:Point):void
		{
			this.startPoint_ = startPoint;
		}
		
		public function set endPoint( endPoint:Point):void
		{
			this.endPoint_ = endPoint;
		}
		
		public function setStart( x:Number, y:Number):void
		{
			this.startPoint = new Point(x, y);
		}
		
		public function setEnd( x:Number, y:Number):void
		{
			this.endPoint = new Point(x, y);
		}
		
		public function get width():Number
		{
			return this.width_; 
		}
		
		public function set width(width:Number ):void
		{
			this.width_ = width;
		}
		
		// read-only properties.
		public function get labels():DisplayLabelGroup
		{
			return labels_;
		}
		
		public function get title():DisplayTextLabel
		{
			return this.title_;
		}
		
		public function get sticks():DisplayStickGroup
		{
			return this.sticks_;
		}
		
		public function get axis():Axis
		{
			return this.dataModel as Axis;
		}
		
		public function get parent():DisplayBarChart
		{
			return this.parent_;
		}
		
		public function toString():String
		{
			var str:String = "\nObject:DispalyAxis ";
			str += "[width = " + width + "]";
			str += "[startPosition: x = " + startPoint.x + ", y = " + startPoint.y + "]";
			str += "[endPosition: x = " + endPoint_.x + ", y = " + endPoint_.y + "]";
			str += sticks;
			str += labels;
			str += title;
			return str;
		}
	}
	
}